<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增用户数据库')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-userDatabase-add">
            <input name="databaseId"  id="databaseId" type="hidden">

            <div class="form-group">
                <label class="col-sm-3 control-label">数据库名称：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" type="text" name="databaseName" onclick="selectDatabaseToCallBack()" id="databaseName" >
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">别名：</label>
                <div class="col-sm-8">
                    <input name="alias" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">状态：</label>
                <div class="col-sm-8">
                    <select name="status" class="form-control m-b" th:with="type=${@dict.getType('database_user_status')}" required>
                        <option th:each="dict : ${type}" th:if="${dict.dictValue} == '0' or  ${dict.dictValue} == '1'" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" ></option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "datamonitor/myUserDatabase";
        $("#form-userDatabase-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-userDatabase-add').serialize());
            }
        }

        // 选择用户
        function selectUsersToCallBack() {
            var options = {
                title: '选择用户',
                url: ctx + "common/modal/parent/sysUser",
                callBack: selectUsers2Submit
            };
            $.modal.openOptions(options);
        }

        function selectUsers2Submit(index, layero) {
            var body = $.modal.getChildFrame(index);
            $("#userId").val(body.find('#userId').val());
            $("#userName").val(body.find('#userName').val());
            $.modal.close(index);
        }

        // 选择数据库
        function selectDatabaseToCallBack() {
            var options = {
                title: '选择数据库',
                url: ctx + "common/modal/parent/tmdDatabase",
                callBack: selectDatabase2Submit
            };
            $.modal.openOptions(options);
        }

        function selectDatabase2Submit(index, layero) {
            var body = $.modal.getChildFrame(index);
            $("#databaseId").val(body.find('#databaseId').val());
            $("#databaseName").val(body.find('#databaseName').val());
            $.modal.close(index);
        }

    </script>
</body>
</html>